package com.song.boot.dao;

import com.song.boot.pojo.Person;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/12/22
 * @Version 1.0
 **/
@Transactional
public interface PersonDao extends JpaRepository<Person, Long> {
    //自定义的查询
    //原则：无需编写sql（约定由于配置）
    List<Person> findAllByName(String name);
   // List<Person> findAllByNameContaining(String name);

    List<Person> findAllByAgeBetween(Integer age1, Integer age2);

    Page<Person> findAllByNameContaining(String name, Pageable pageable);

    List<Person> findAllByAgeLessThan(Integer age);

    //原生sql：

    @Modifying
    @Query("update Person set name=?1 where id=?2") //基于HQL
    void updateTest1(String name, Long id);

    @Modifying
    @Query(value = "update t_person set name=?1 where id=?2",nativeQuery = true)
    void updateTest2(String name, Long id);


}
